<?php
namespace app\cms\controller;

use app\common\controller\Front;

class Index extends Front
{
    private $info = [];
    
    private $items = [];
    
    public function _initialize()
    {
        parent::_initialize();
    }
    
    public function index()
    {
        return $this->common('index');
    }
    
    //空操作
    public function _empty($action='')
    {
        if(!in_array($action,explode(',',config('cms.action_name')))){
            $this->error(lang('cmsErrorParams'));
        }
        $this->common($action);
        $this->assign($this->info);
        $this->assign($this->items);
        return $this->fetch();
    }
    
    //公共操作
    private function common($action='index')
    {
        //最大偏移量
        if(config('cms.page_max_'.$action) && $this->site['page'] > config('cms.page_max_'.$action)){
            $this->error(lang('cmsErrorMax'));
        }
        //公共参数
        $this->info['pageNumber']     = $this->site['page'];
        $this->info['pageSize']       = intval(config('cms.limit_index_'.$action));
        $this->info['pagePath']       = DcUrl('cms/index/'.$action,['pageNumber'=>'[PAGE]']);
        //TKD
        $this->info['seoTitle']       = cmsSeo(lang(camelize('cms_title_index_'.$action)),$this->site['page']);
        $this->info['seoKeywords']    = cmsSeo(lang(camelize('cms_keywords_index_'.$action)),$this->site['page']);
        $this->info['seoDescription'] = cmsSeo(lang(camelize('cms_description_index_'.$action)),$this->site['page']);
        //禁用分页
        if($this->info['pageSize'] < 1){
            $this->assign($this->info);
            return $this->fetch();
        }
        //分页查询
        $this->items = cmsSelect([
            'cache'    => true,
            'status'   => 'normal',
            'action'   => $action,
            'controll' => 'detail',
            'module'   => 'cms',
            'field'    => config('cms.field_select'),
            'simple'   => cmsValue(config('cms.total_index_'.$action)),
            'sort'     => DcEmpty(config('cms.sort_index_'.$action),'info_id'),
            'order'    => 'desc',
            'paginate' => [
                'list_rows' => $this->info['pageSize'],
                'page'      => $this->info['pageNumber'],
                'path'      => $this->info['pagePath'],
            ]
        ]);
        //加载模板
        $this->assign($this->info);
        $this->assign($this->items);
        return $this->fetch();
    }
}